package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.pro.domain.dao.LabelGroupDao;
import com.xbongbong.pro.domain.entity.LabelGroupEntity;
import com.xbongbong.saas.model.LabelGroupModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author guohui.zhang
 * @Title:
 * @date 2020/11/219:19
 */
@Service("labelGroupModel")
public class LabelGroupModelImpl implements LabelGroupModel {
    @Resource
    private LabelGroupDao labelGroupDao;


    @Override
    public Integer insert(LabelGroupEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        entity.setDel(DelEnum.NORMAL.getDel());
        return labelGroupDao.insert(entity);
    }

    @Override
    public Integer update(LabelGroupEntity entity) throws XbbException {
        entity.setUpdateTime(DateTimeUtil.getInt());
        return labelGroupDao.update(entity);
    }

    @Override
    public List<LabelGroupEntity> findEntitys(Map<String, Object> param) {
        return labelGroupDao.findEntitys(param);
    }

    @Override
    public  Integer getEntitysCount(Map<String, Object> param) {
        return labelGroupDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(LabelGroupEntity entity) throws XbbException {
        if (entity.getId() == null || Objects.equals(0L, entity.getId())) {
            return insert(entity);
        }
        return update(entity);
    }

    @Override
    public LabelGroupEntity getByKey(Long key, String corpid) {
        return labelGroupDao.getByKey(key, corpid);
    }

    @Override
    public Integer sortCategory(Map<String, Object> param, Map<Long, Long> sortMap) {
        return labelGroupDao.sort(param, sortMap);
    }

    @Override
    public Integer deleteBykey(Long key, String corpid) {
        return labelGroupDao.deleteByKey(key, corpid);
    }

    @Override
    public void insertBatch(List<LabelGroupEntity> entitys, String corpid) {
         labelGroupDao.insertBatch(entitys);
    }

    @Override
    public List<LabelGroupEntity> getByIds(List<Long> groupIds, String corpid) {
        return labelGroupDao.getByIds(groupIds, corpid);
    }

    @Override
    public void deletebatch(List<Long> groupIds, String corpid) {
        labelGroupDao.deleteBatch(groupIds, corpid);
    }

    @Override
    public void updateBatch(List<LabelGroupEntity> entitys, String corpid) {
        labelGroupDao.updateBatch(entitys,corpid);
    }

    @Override
    public void deleteByFormIds(Collection<Long> systemFormList, String targetCorpid, Long appId) {
        labelGroupDao.deleteByFormIds(systemFormList, targetCorpid,appId);
    }
}
